﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class frm_FeeReim : System.Web.UI.Page
{
    #region  费用报销业务逻辑主体部分

    //获得主表信息
    private void GetInfoByMain(string strCurrUserID, int Type)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();
        cls_Property.SetOrGetDataSetType = Type;

        ClsFeeReimDAL cls_FeeReimDAL = new ClsFeeReimDAL();

        DataSet dst = cls_FeeReimDAL.GetFeeReimDataSet(strCurrUserID, Type);

        if (dst != null && dst.Tables[0].Rows.Count > 0)
        {
            cls_Property.SetOrGetCorporationDataSet = dst;

            this.BindByDataView(dst, 0);
        }
        else
        {
            this.dgrdResult.CurrentPageIndex = 0;
            this.dgrdResult.DataSource = null;
            this.dgrdResult.DataBind();
            this.lblRsCounts.Text = "共0条记录";
            this.lblPageCounts.Text = "共0页";
            this.lblCurrPage.Text = "当前第0页";
            this.lbtnFirst.Enabled = this.lbtnPrev.Enabled = this.lbtnNext.Enabled = this.lbtnEnd.Enabled = this.txtGo.Enabled = false;
            this.lblRsCounts.Enabled = this.lblPageCounts.Enabled = this.lblCurrPage.Enabled = this.lblGoTxt1.Enabled = this.lblGoTxt2.Enabled = false;
        }
    }

    //获得从表信息
    public void OpenChildResult(object sender, ImageClickEventArgs e)
    {
        //获取当前登录用户ID
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();

        string strUserID = cls_Property.SetOrGetUserID;

        if (strUserID != "")
        {
            //获取当前的ImageButton控件
            ImageButton ibtnOpen = (ImageButton)sender;

            //获取要操作当前项的类型(0展开，1收缩)和当前项再DataGrid中的索引位置
            int intCommandName = Int32.Parse(ibtnOpen.CommandName);
            int intIndex = Int32.Parse(ibtnOpen.CommandArgument);

            //获取当前项中要控制的控件
            CheckBox chkRsSelect = (CheckBox)this.dgrdResult.Items[intIndex].FindControl("chkRsSelect");
            ImageButton ibtnOpenChild = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnOpenChild");
            ImageButton ibtnRsCancel = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsCancel");
            ImageButton ibtnRsEdit = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsEdit");
            ImageButton ibtnRsServer = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsServer");
            ImageButton ibtnRsOAudit = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsOAudit");
            Panel panShowChildResult = (Panel)this.dgrdResult.Items[intIndex].FindControl("panShowChildResult");

            //获取当前项中该项单据从表信息
            ClsFeeReimDAL cls_FeeReimDAL = new ClsFeeReimDAL();
            CuTextBox ctbRs0 = (CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbRs0");
            DataSet dst = cls_FeeReimDAL.GetFeeReimChildDataSet(ctbRs0.Text.Trim());

            //当前项中该单据从表中的信息为空时，者注册提示信息(收缩时用)
            if (dst == null || dst.Tables[0].Rows.Count <= 0)
            {
                ibtnOpen.Attributes.Add("OnClick", "return confirm('单据录入未完成，您要作废此单据吗？');");
            }

            //展开当前项中该单据主从表信息控制相关
            if (intCommandName == 0)
            {
                //保存当前单据客户的编号用户弹出窗口查询数据
                string strCusNo = strUserID;
                this.Page.Session["CustomerNo"] = strCusNo;

                //绑定从表中的信息
                if (dst != null && dst.Tables[0].Rows.Count > 0)
                {
                    DataGrid dgrd = (DataGrid)this.dgrdResult.Items[intIndex].FindControl("dgrdChildResult");

                    this.BindChildByDataView(dgrd, dst, 0);
                }

                //用循环找到当前展开的项将其展开
                int intCount = this.dgrdResult.Items.Count;

                for (int i = 0; i < intCount; i++)
                {
                    Panel panItem = (Panel)this.dgrdResult.Items[i].FindControl("panItem");

                    panItem.Visible = (i == intIndex) ? true : false;
                }

                //主表展开后则主表不可操作控制
                this.ibtnAdd.CommandArgument = intIndex.ToString();
                this.ibtnAdd.CommandName = "5";
                this.ibtnRef.CommandName = "1";
                ibtnOpenChild.CommandName = "1";
                ibtnOpenChild.ImageUrl = "../App_Images/ico/10.gif";
                ibtnRsEdit.ImageUrl = "../App_Images/ico/14.gif";
                ibtnRsServer.ImageUrl = "../App_Images/ico/16.gif";
                ibtnRsOAudit.ImageUrl = "../App_Images/ico/17.gif";
                ibtnRsCancel.ImageUrl = "../App_Images/ico/18.gif";
                this.ibtnAudit.ImageUrl = "../App_Images/b_21_3.gif";
                panShowChildResult.Visible = true;
                this.ibtnAudit.Enabled = chkRsSelect.Enabled = ibtnRsCancel.Enabled = ibtnRsEdit.Enabled = ibtnRsServer.Enabled = ibtnRsOAudit.Enabled = false;
                this.lblRsCounts.Enabled = this.lblPageCounts.Enabled = this.lblCurrPage.Enabled = this.lbtnFirst.Enabled = this.lbtnPrev.Enabled = this.lbtnNext.Enabled = this.lbtnEnd.Enabled = this.lblGoTxt1.Enabled = this.txtGo.Enabled = this.lblGoTxt2.Enabled = false;

                //获取当前项中该项单据的状态(是否已确认，是否已终止)
                bool is_audit = bool.Parse(this.dgrdResult.Items[intIndex].Cells[2].Text);
                bool is_visible = bool.Parse(this.dgrdResult.Items[intIndex].Cells[3].Text);

                //如果主表确认或终止后则从表不可操作(添加和作废)
                if (is_audit || is_visible)
                {
                    this.ibtnAdd.Enabled = this.ibtnDelete0.Enabled = false;
                    this.ibtnAdd.ImageUrl = "../App_Images/b_18_3.gif";
                    this.ibtnDelete0.ImageUrl = "../App_Images/b_19_5.gif";
                    this.imgDelete.ImageUrl = "../App_Images/b_19_6.gif";
                    this.imgDelete.Attributes.Add("OnMouseOver", "");
                    this.imgDelete.Attributes.Add("OnMouseOut", "");
                    this.imgDelete.Attributes.Add("OnClick", "");
                }
            }
            else//收缩当前项中该单据主表信息控制相关
            {
                this.ibtnAdd.CommandName = "0";
                this.ibtnRef.CommandName = "0";
                ibtnOpenChild.CommandName = "0";
                ibtnOpenChild.ImageUrl = "../App_Images/ico/9.gif";
                ibtnRsEdit.ImageUrl = "../App_Images/ico/12.gif";
                ibtnRsServer.ImageUrl = "../App_Images/ico/11.gif";
                ibtnRsOAudit.ImageUrl = "../App_Images/ico/8.gif";
                ibtnRsCancel.ImageUrl = "../App_Images/ico/4.gif";
                this.ibtnAudit.ImageUrl = "../App_Images/b_21_1.gif";
                this.ibtnAdd.ImageUrl = "../App_Images/b_18_1.gif";
                this.ibtnDelete0.ImageUrl = "../App_Images/b_19_1.gif";
                this.imgDelete.ImageUrl = "../App_Images/b_19_4.gif";
                this.imgDelete.Attributes.Add("OnMouseOver", "ChangImage(this, '../App_Images/b_19_3.gif');ChangImage(document.all.ibtnDelete0, '../App_Images/b_19_2.gif')");
                this.imgDelete.Attributes.Add("OnMouseOut", "ChangImage(this, '../App_Images/b_19_4.gif');ChangImage(document.all.ibtnDelete0, '../App_Images/b_19_1.gif')");
                this.imgDelete.Attributes.Add("OnClick", "ChildMenuVisible()");
                panShowChildResult.Visible = false;
                this.ibtnAdd.Enabled = this.ibtnDelete0.Enabled = this.ibtnAudit.Enabled = chkRsSelect.Enabled = ibtnRsCancel.Enabled = ibtnRsEdit.Enabled = ibtnRsServer.Enabled = ibtnRsOAudit.Enabled = true;

                //收缩时判断从表中是否有记录，没有则收缩后作废该主表信息
                if (dst == null || dst.Tables[0].Rows.Count <= 0)
                {
                    int intID = Int32.Parse(this.dgrdResult.Items[intIndex].Cells[1].Text.Trim());
                    Boolean is_Succeed = cls_FeeReimDAL.DeleteInfo(intID, 1);
                }

                //重新绑定主表数据
                this.GetInfoByMain(strUserID, cls_Property.SetOrGetDataSetType);
            }
        }
        else
        {
            this.Page.Session.Remove("SetOrGetUserID");
            this.lblJs.Text = "<script>parent.window.location.href='../index.aspx'</script>";
        }
    }

    //增加主从表
    public void AddInfo(object sender, EventArgs e)
    {
        //获取当前登录用户ID
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();
        ClsMenuDAL cls_Menu = new ClsMenuDAL();

        string strUserID = cls_Property.SetOrGetUserID;

        if (strUserID != "")
        {
            ClsFeeReimDAL cls_FeeReimDAL = new ClsFeeReimDAL();

            //获取当前的ImageButton控件
            ImageButton ibtnAdd = (ImageButton)sender;

            //获取要操作的类型(0打开主表添加面板,1关闭主表添加面板,2保存主表添加记录,3关闭从表添加面板,4保存从表添加记录,5打开从表添加面板)
            int intCommandName = Int32.Parse(ibtnAdd.CommandName);

            //打开主表添加面板
            if (intCommandName == 0)
            {
                if (!this.panAddResult.Visible)
                {
                    //获取系统编码
                    string strCode = cls_Menu.GetSystemCode("0", "00", "", 10);

                    if (strCode != "Error")
                    {
                        this.panAddResult.Visible = true;
                        this.ctbAdd0.Text = strCode;
                        this.ctsbAdd0.Text = this.ctbAdd7.Text = DateTime.Now.ToString();
                        this.ctbAdd6.Text = strUserID;
                        this.lblJs.Text = "<script>document.getElementById('" + this.ctsbAdd0.ClientID + "_txtBox').focus();</script>";
                    }
                    else
                    {
                        this.lblJs.Text = "<script>alert('新增记录失败，请重试！')</script>";
                    }
                }
            }

            //关闭主表添加面板
            else if (intCommandName == 1)
            {
                this.panAddResult.Visible = false;

                //取消当前系统编码
                string strMessage = cls_Menu.GetSystemCode("1", "00", this.ctbAdd0.Text.Trim(), 10);
            }

            //保存主表添加记录
            else if (intCommandName == 2)
            {
                string strNo = this.ctbAdd0.Text.Trim();
                string strDate = this.ctsbAdd0.Text.Trim();
                string strDpNo = this.ctsbAdd1.Text.Trim();


                string bsccw = this.ctbAdd3.Text.Trim();
                string bscjl = this.ctbAdd4.Text.Trim();
                string bxr = this.ctbAdd5.Text.Trim();

                string strRemark = this.ctbAdd10.Text.Trim();

                Boolean bolIsSucceed = cls_FeeReimDAL.AddOrUpdateInfo(-1,strNo, DateTime.Parse(strDate), strDpNo,bsccw,bscjl,bxr, strUserID, strRemark);
                
                if (bolIsSucceed)
                {
                    //重新绑定结果
                    this.GetInfoByMain(strUserID, cls_Property.SetOrGetDataSetType);

                    //主表新增后直接打开从表进行新增从表记录
                    this.panAddResult.Visible = false;
                    ImageButton ibtn = new ImageButton();

                    int intItems = this.dgrdResult.Items.Count - 1;

                    for (int i = intItems; i >= 0; i--)
                    {
                        string strRs_NO = ((CuTextBox)this.dgrdResult.Items[i].FindControl("ctbRs0")).Text.Trim();

                        if (strRs_NO == strNo)
                        {
                            ibtn = (ImageButton)this.dgrdResult.Items[i].FindControl("ibtnOpenChild");

                            break;
                        }
                    }

                    if (ibtn != null)
                    {
                        this.OpenChildResult(ibtn, null);
                        this.AddInfo(this.ibtnAdd, null);
                    }
                }
                else
                {
                    this.lblJs.Text = "<script>alert('新增记录失败，请重试！')</script>";
                }
            }
            //////////////////////////////////////////从表相关操作/////////////////////////////////////
            else
            {
                int intIndex = Int32.Parse(this.ibtnAdd.CommandArgument);

                Panel panChildAddResult = (Panel)this.dgrdResult.Items[intIndex].FindControl("panChildAddResult");
                CuTextBox Price = (CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbChildAdd4");

                //关闭从表添加面板
                if (intCommandName == 3)
                {
                    panChildAddResult.Visible = false;
                }

                //保存从表添加记录
                else if (intCommandName == 4)
                {

                    string r_no = ((CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbRs0")).Text.Trim();
                    string up_no = ((CuTextSelectBox)this.dgrdResult.Items[intIndex].FindControl("ctsbChildAdd0")).Text.Trim();
                    string im_no = ((CuTextBox)this.dgrdResult.Items[intIndex].FindControl("CuTextBox7")).Text.Trim();
                    decimal a_money = decimal.Parse(((CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbChildAdd10")).Text.Trim());
                    decimal b_money = decimal.Parse(((CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbChildAdd11")).Text.Trim());
                    decimal c_money = decimal.Parse(((CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbChildAdd12")).Text.Trim());
                    decimal d_money = decimal.Parse(((CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbChildAdd13")).Text.Trim());
                    string Remark = ((CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbChildAdd14")).Text.Trim();

                    Boolean bolIsSucceed = cls_FeeReimDAL.AddOrUpdateChild(-1, r_no, up_no, im_no, a_money, b_money, c_money, d_money, Remark);

                    if (bolIsSucceed)
                    {
                        panChildAddResult.Visible = false;

                        DataSet dst = cls_FeeReimDAL.GetFeeReimChildDataSet(r_no);

                        if (dst != null && dst.Tables[0].Rows.Count > 0)
                        {
                            //重新绑定从表信息
                            DataGrid dgrd = (DataGrid)this.dgrdResult.Items[intIndex].FindControl("dgrdChildResult");

                            this.BindChildByDataView(dgrd, dst, 0);
                        }

                        ((ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnOpenChild")).Attributes.Remove("OnClick");
                    }
                    else
                    {
                        this.lblJs.Text = "<script>alert('新增记录失败，请重试！')</script>";
                    }
                }

                //打开从表添加面板
                else if (intCommandName == 5)
                {
                    panChildAddResult.Visible = true;

                    CuTextSelectBox ctsbChildAdd0 = (CuTextSelectBox)this.dgrdResult.Items[intIndex].FindControl("ctsbChildAdd0");
                    this.lblJs.Text = "<script>document.getElementById('" + ctsbChildAdd0.ClientID + "_txtBox').focus();</script>";
                }
            }
        }
        else
        {
            //取消当前系统编码
            string strMessage = cls_Menu.GetSystemCode("1", "00", this.ctbAdd0.Text.Trim(), 10);
            this.Page.Session.Remove("SetOrGetUserID");
            this.lblJs.Text = "<script>parent.window.location.href='../index.aspx'</script>";
        }
    }

    //修改主从表/确认主从表
    public void UpDateInfo(object sender, EventArgs e)
    {
        //获取当前登录用户ID
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();

        string strUserID = cls_Property.SetOrGetUserID;

        if (strUserID != "")
        {
            ClsFeeReimDAL cls_FeeReimDAL = new ClsFeeReimDAL();

            //获取当前的ImageButton控件
            ImageButton ibtnUpdate = (ImageButton)sender;

            //获取要操作的类型(0主表确认，1取消主表编辑,2打开主表编辑 3主表取消确认,4保存主表编辑，5取消从表编辑，6打开从表编辑，7保存从表编辑)和当前项再DataGrid中的索引位置
            int intCommandName = Int32.Parse(ibtnUpdate.CommandName);
            int intIndex = Int32.Parse(ibtnUpdate.CommandArgument);

            //主表确认相关(可批量确认)
            if (intCommandName == 0)
            {
                int intCount = this.dgrdResult.Items.Count;

                for (int i = 0; i < intCount; i++)
                {
                    //是否选中确认
                    bool IsChecked = ((CheckBox)this.dgrdResult.Items[i].FindControl("chkRsSelect")).Checked;

                    if (IsChecked)
                    {
                        //判断此单是否确认
                        int intID = Int32.Parse(this.dgrdResult.Items[i].Cells[1].Text.Trim());
                        bool is_Audit = bool.Parse(this.dgrdResult.Items[i].Cells[2].Text.Trim());

                        if (!is_Audit)
                        {
                            //判断该单据的确认设置(无需确认还是单审还时多审)
                            ClsMenuDAL cls_Menu = new ClsMenuDAL();
                            DataSet dstAudit = cls_Menu.GetAuditSetMessageDataSet(Int32.Parse(this.hidCurrPageID.Value.Trim()));

                            if (dstAudit != null && dstAudit.Tables[0].Rows.Count > 0)
                            {
                                //单次确认
                                if (dstAudit.Tables[0].Rows.Count == 1)
                                {
                                    //获取当前登录用户在确认设置中对应的岗位
                                    ClsAuditDAL cls_AuditDAL = new ClsAuditDAL();
                                    string strCurrUserStation = cls_AuditDAL.GetUserAuditStation(strUserID, Int32.Parse(this.hidCurrPageID.Value.Trim()));

                                    //如果当前登录用户在确认设置中没有对应的岗位则无权确认
                                    if (strCurrUserStation != "")
                                    {
                                        Boolean bolIsSucceed = cls_FeeReimDAL.AuditOrOAuditFeeReimInfo(intID, strUserID, 0);
                                    }
                                    else
                                    {
                                        this.lblJs.Text = "<script>alert('您无权确认此单据！')</script>";
                                    }
                                }
                                else//多确认
                                {
                                    string strCm_No = ((CuTextBox)this.dgrdResult.Items[i].FindControl("ctbRs0")).Text.Trim();
                                    this.lblJs.Text = "<script>ModalDialog('../Mod_QueryFrom/frm_Audit.aspx?PageID=" + this.hidCurrPageID.Value.Trim() + "&C_No=" + strCm_No + "', 463, 390);</script>";
                                }
                            }
                            else//无需确认
                            {
                                Boolean bolIsSucceed = cls_FeeReimDAL.AuditOrOAuditFeeReimInfo(intID, strUserID, 0);
                            }
                        }
                        else
                        {
                            this.lblJs.Text = "<script>alert('此单已确认！')</script>";
                        }
                    }
                }

                //重新绑定主表信息
                this.GetInfoByMain(strUserID, cls_Property.SetOrGetDataSetType);
            }

            //主表取消确认相关(不可批量取消确认)
            else if (intCommandName == 3)
            {
                //获取要取消确认的单据ID
                int intID = Int32.Parse(this.dgrdResult.Items[intIndex].Cells[1].Text.Trim());
                string strCm_No = ((CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbRs0")).Text.Trim();

                //判断单据确认设置
                ClsMenuDAL cls_Menu = new ClsMenuDAL();
                DataSet dstAudit = cls_Menu.GetAuditSetMessageDataSet(Int32.Parse(this.hidCurrPageID.Value));

                if (dstAudit != null && dstAudit.Tables[0].Rows.Count > 0)
                {
                    //获取当前登录用户在确认设置中对应的岗位
                    ClsAuditDAL cls_AuditDAL = new ClsAuditDAL();

                    string strCurrUserStation = cls_AuditDAL.GetUserAuditStation(strUserID, Int32.Parse(this.hidCurrPageID.Value));

                    //如果当前登录用户在确认设置中没有对应的岗位则无权取消确认
                    if (strCurrUserStation != "")
                    {
                        //获取该单据终审岗位
                        string strEndAuditStation = cls_AuditDAL.GetEndAuditStation(Int32.Parse(this.hidCurrPageID.Value));

                        //如果当前登录用户没有达到取消确认的岗位则无权取消确认
                        if (strEndAuditStation == strCurrUserStation)
                        {
                            Boolean bolIsSucceed = cls_FeeReimDAL.AuditOrOAuditFeeReimInfo(intID, strUserID, 1);

                            if (bolIsSucceed)
                            {
                                //重新绑定主表信息
                                this.GetInfoByMain(strUserID, cls_Property.SetOrGetDataSetType);
                                cls_AuditDAL.DeleteAuditMsg(strCm_No);
                            }
                            else
                            {
                                this.lblJs.Text = "<script>alert('取消确认失败，请重试！')</script>";
                            }
                        }
                        else
                        {
                            this.lblJs.Text = "<script>alert('您无权取消确认此单据！')</script>";
                        }
                    }
                    else
                    {
                        this.lblJs.Text = "<script>alert('您无权取消确认此单据！')</script>";
                    }
                }
                else
                {
                    Boolean bolIsSucceed = cls_FeeReimDAL.AuditOrOAuditFeeReimInfo(intID, strUserID, 1);

                    if (bolIsSucceed)
                    {
                        //重新绑定主表信息
                        this.GetInfoByMain(strUserID, cls_Property.SetOrGetDataSetType);
                    }
                    else
                    {
                        this.lblJs.Text = "<script>alert('取消确认失败，请重试！')</script>";
                    }
                }
            }

            //主表编辑相关
            else if (intCommandName == 1 || intCommandName == 2 || intCommandName == 4)
            {
                //获取要控制的控件
                CheckBox chkRsSelect = (CheckBox)this.dgrdResult.Items[intIndex].FindControl("chkRsSelect");
                ImageButton ibtnRsCancel = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsCancel");
                ImageButton ibtnRsEdit = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsEdit");
                ImageButton ibtnRsServer = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsServer");
                ImageButton ibtnRsOAudit = (ImageButton)this.dgrdResult.Items[intIndex].FindControl("ibtnRsOAudit");
                CuTextBox ctbRs0 = (CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbRs0");
                CuTextBox ctbRs4 = (CuTextBox)this.dgrdResult.Items[intIndex].FindControl("ctbRs4");
                CuTextSelectBox ctsbRs0 = (CuTextSelectBox)this.dgrdResult.Items[intIndex].FindControl("ctsbRs0");
                CuTextSelectBox ctsbRs1 = (CuTextSelectBox)this.dgrdResult.Items[intIndex].FindControl("ctsbRs1");
                CuTextSelectBox ctsbRs2 = (CuTextSelectBox)this.dgrdResult.Items[intIndex].FindControl("ctsbRs2");
                CuTextSelectBox ctsbRs3 = (CuTextSelectBox)this.dgrdResult.Items[intIndex].FindControl("ctsbRs3");
                CuTextSelectBox ctsbRs4 = (CuTextSelectBox)this.dgrdResult.Items[intIndex].FindControl("ctsbRs4");

                //取消编辑
                if (intCommandName == 1)
                {
                    //重新绑定主表信息 
                    this.GetInfoByMain(strUserID, cls_Property.SetOrGetDataSetType);
                }
                //打开编辑
                else if (intCommandName == 2)
                {
                    //ctsbRs1.Text = ctsbRs1.ToolTip;
                    ctsbRs2.Text = ctsbRs2.ToolTip;
                    //ctsbRs3.Text = ctsbRs3.ToolTip;
                    //ctsbRs4.Text = ctsbRs4.ToolTip;
                    ibtnRsCancel.Visible = ibtnRsServer.Visible = true;
                    chkRsSelect.Visible = ibtnRsEdit.Visible = ibtnRsOAudit.Visible = false;
                    ctsbRs0.ReadOnly = false;
                    ctsbRs2.ReadOnly = false;
                    this.lblJs.Text = "<script>document.getElementById('" + ctsbRs0.ClientID + "_txtBox').select();document.getElementById('" + ctsbRs0.ClientID + "_txtBox').focus();</script>";
                }
                //保存编辑
                else
                {
                    int intID = Int32.Parse(this.dgrdResult.Items[intIndex].Cells[1].Text.Trim());

                    //Boolean bolIsSucceed = cls_FeeReimDAL.AddOrUpdateInfo(intID, ctbRs0.Text.Trim(), DateTime.Parse(ctsbRs0.Text.Trim()), ctsbRs4.Text.Trim(), strUserID, ctbRs4.Text.Trim());
                    Boolean bolIsSucceed = false;
                    if (bolIsSucceed)
                    {
                        //重新绑定主表信息
                        this.GetInfoByMain(strUserID, cls_Property.SetOrGetDataSetType);
                    }
                    else
                    {
                        this.lblJs.Text = "<script>alert('修改记录失败，请重试！')</script>";
                    }
                }
            }
            //////////////////////////////////////////从表相关操作/////////////////////////////////////
            else
            {
                DataGrid dgrd = new DataGrid();
                string strCm_No = "";
                int intItems = this.dgrdResult.Items.Count;

                //找当前可见的子DataGrid
                for (int i = intItems - 1; i >= 0; i--)
                {
                    Panel panItem = (Panel)this.dgrdResult.Items[i].FindControl("panItem");

                    if (panItem.Visible)
                    {
                        dgrd = (DataGrid)this.dgrdResult.Items[i].FindControl("dgrdChildResult");
                        strCm_No = ((CuTextBox)this.dgrdResult.Items[i].FindControl("ctbRs0")).Text.Trim();
                        break;
                    }
                }

                //在子DataGrid中找要操作的控件
                CheckBox chkChildRsSelect = (CheckBox)dgrd.Items[intIndex].FindControl("chkChildRsSelect");
                ImageButton ibtnChildRsCancel = (ImageButton)dgrd.Items[intIndex].FindControl("ibtnChildRsCancel");
                ImageButton ibtnChildRsEdit = (ImageButton)dgrd.Items[intIndex].FindControl("ibtnChildRsEdit");
                ImageButton ibtnChildRsServer = (ImageButton)dgrd.Items[intIndex].FindControl("ibtnChildRsServer");
                CuTextSelectBox ctsbChildRs0 = (CuTextSelectBox)dgrd.Items[intIndex].FindControl("ctsbChildRs0");
                CuTextBox ctbChildRs0 = (CuTextBox)dgrd.Items[intIndex].FindControl("ctbChildRs0");

                CuTextBox ctbChildRs11 = (CuTextBox)dgrd.Items[intIndex].FindControl("ctbChildRs11");
                CuTextBox ctbChildRs12 = (CuTextBox)dgrd.Items[intIndex].FindControl("ctbChildRs12");
                CuTextBox ctbChildRs13 = (CuTextBox)dgrd.Items[intIndex].FindControl("ctbChildRs13");
                CuTextBox ctbChildRs14 = (CuTextBox)dgrd.Items[intIndex].FindControl("ctbChildRs14");
                CuTextBox ctbChildRs15 = (CuTextBox)dgrd.Items[intIndex].FindControl("ctbChildRs15");

                //取消编辑
                if (intCommandName == 5)
                {
                    DataSet dst = cls_FeeReimDAL.GetFeeReimChildDataSet(strCm_No);

                    if (dst != null && dst.Tables[0].Rows.Count > 0)
                    {
                        this.BindChildByDataView(dgrd, dst, 0);
                    }
                }
                //打开编辑
                else if (intCommandName == 6)
                {
                    chkChildRsSelect.Visible = ibtnChildRsEdit.Visible = false;
                    ibtnChildRsCancel.Visible = ibtnChildRsServer.Visible = true;
                    ctbChildRs11.ReadOnly = ctbChildRs12.ReadOnly = ctbChildRs13.ReadOnly = ctbChildRs14.ReadOnly = ctbChildRs15.ReadOnly = false;
                    this.lblJs.Text = "<script>document.getElementById('" + ctbChildRs11.ClientID + "_txtBox').select();document.getElementById('" + ctbChildRs11.ClientID + "_txtBox').focus();</script>";
                }
                //保存编辑
                else
                {
                    int intID = Int32.Parse(dgrd.Items[intIndex].Cells[1].Text.Trim());
                    //string im_no = ctbChildRs0.Text.Trim();
                    decimal a_money = decimal.Parse(ctbChildRs11.Text.Trim());
                    decimal b_money = decimal.Parse(ctbChildRs12.Text.Trim());
                    decimal c_money = decimal.Parse(ctbChildRs13.Text.Trim());
                    decimal d_money = decimal.Parse(ctbChildRs14.Text.Trim());
                    string Remark = ctbChildRs15.Text.Trim();

                    Boolean bolIsSucceed = cls_FeeReimDAL.AddOrUpdateChild(intID, "","", "", a_money, b_money, c_money, d_money, Remark);

                    if (bolIsSucceed)
                    {
                        //重新绑定从表信息
                        DataSet dst = cls_FeeReimDAL.GetFeeReimChildDataSet(strCm_No);

                        if (dst != null && dst.Tables[0].Rows.Count > 0)
                        {
                            this.BindChildByDataView(dgrd, dst, 0);
                        }
                    }
                    else
                    {
                        this.lblJs.Text = "<script>alert('修改记录失败，请重试！')</script>";
                    }
                    
                }
            }
        }
        else
        {
            ClsMenuDAL cls_Menu = new ClsMenuDAL();
            string strMessage = cls_Menu.GetSystemCode("1", "00", this.ctbAdd0.Text.Trim(), 10);//取消当前系统编码
            this.Page.Session.Remove("SetOrGetUserID");
            this.lblJs.Text = "<script>parent.window.location.href='../index.aspx'</script>";
        }
    }

    //删除主从表
    private void DeleteStockCheckInfo(int CommandName)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();

        string strUserID = cls_Property.SetOrGetUserID;

        if (strUserID != "")
        {
            ClsFeeReimDAL cls_FeeReimDAL = new ClsFeeReimDAL();
            int intCount = this.dgrdResult.Items.Count;
            int intcommand = Int32.Parse(this.ibtnRef.CommandName);

            if (intcommand == 0)//作废主表
            {
                for (int i = 0; i < intCount; i++)
                {
                    bool IsChecked = ((CheckBox)this.dgrdResult.Items[i].FindControl("chkRsSelect")).Checked;

                    if (IsChecked)
                    {
                        bool is_audit = bool.Parse(this.dgrdResult.Items[i].Cells[2].Text.Trim());

                        if (!is_audit)
                        {
                            Boolean bolIsSucceed = false;
                            int intID = Int32.Parse(this.dgrdResult.Items[i].Cells[1].Text.Trim());

                            if (CommandName == 0)//不彻底作废
                            {
                                bolIsSucceed = cls_FeeReimDAL.DeleteInfo(intID, 0);
                            }
                            else//彻底作废
                            {
                                bolIsSucceed = cls_FeeReimDAL.DeleteInfo(intID, 1);
                            }

                            if (!bolIsSucceed)
                            {
                                this.lblJs.Text = "<script>alert('作废记录失败，请重试！')</script>";
                            }
                        }
                        else
                        {
                            this.lblJs.Text = "<script>alert('此单已确认，不能作废！')</script>";
                        }
                    }
                }

                //重新绑定主表结果
                this.GetInfoByMain(strUserID, cls_Property.SetOrGetDataSetType);
            }
            else//作废从表
            {
                DataGrid dgrd = new DataGrid();
                string strCm_No = "";
                int intItems = this.dgrdResult.Items.Count;

                for (int i = intItems - 1; i >= 0; i--)//找当前可见的子DataGrid
                {
                    Panel panItem = (Panel)this.dgrdResult.Items[i].FindControl("panItem");

                    if (panItem.Visible)
                    {
                        dgrd = (DataGrid)this.dgrdResult.Items[i].FindControl("dgrdChildResult");
                        strCm_No = ((CuTextBox)this.dgrdResult.Items[i].FindControl("ctbRs0")).Text.Trim();
                        break;
                    }
                }

                int intChildItems = dgrd.Items.Count;//循环作废所选的项

                for (int j = intChildItems - 1; j >= 0; j--)
                {
                    bool IsChecked = ((CheckBox)dgrd.Items[j].FindControl("chkChildRsSelect")).Checked;

                    if (IsChecked)
                    {
                        int intID = Int32.Parse(dgrd.Items[j].Cells[1].Text.Trim());
                        string Up_No = ((CuTextBox)dgrd.Items[j].FindControl("ctbChildRs0")).Text.Trim();
                        Boolean bolIsSucceed = false;

                        if (CommandName == 0)//不彻底作废
                        {
                            bolIsSucceed = cls_FeeReimDAL.DeleteChildInfo(intID, 0);
                        }
                        else//彻底作废
                        {
                            bolIsSucceed = cls_FeeReimDAL.DeleteChildInfo(intID, 1);
                        }

                        if (!bolIsSucceed)
                        {
                            this.lblJs.Text = "<script>alert('作废记录失败，请重试！')</script>";
                        }
                    }
                }

                DataSet dst = cls_FeeReimDAL.GetFeeReimChildDataSet(strCm_No);//重新绑定从表结果

                if (dst != null && dst.Tables[0].Rows.Count > 0)
                {
                    this.BindChildByDataView(dgrd, dst, 0);
                }
                else
                {
                    dgrd.CurrentPageIndex = 0;
                    dgrd.DataSource = null;
                    dgrd.DataBind();
                }
            }
        }
        else
        {
            ClsMenuDAL cls_Menu = new ClsMenuDAL();
            string strMessage = cls_Menu.GetSystemCode("1", "00", this.ctbAdd0.Text.Trim(), 10);//取消当前系统编码
            this.Page.Session.Remove("SetOrGetUserID");
            this.lblJs.Text = "<script>parent.window.location.href='../index.aspx'</script>";
        }
    }

    protected void dgrdResult_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        if (e.Item.ItemIndex != -1)
        {
            bool Is_audit = bool.Parse(e.Item.Cells[2].Text.Trim());
            bool Is_visible = bool.Parse(e.Item.Cells[3].Text.Trim());
            string strButtonEdit = this.hidButtonEdit.Value;
            string strButtonOAudit = this.hidButtonOAudit.Value;

            CheckBox chkRsSelect = (CheckBox)e.Item.FindControl("chkRsSelect");
            ImageButton ibtnRsEdit = (ImageButton)e.Item.FindControl("ibtnRsEdit");
            ImageButton ibtnRsCancel = (ImageButton)e.Item.FindControl("ibtnRsCancel");
            ImageButton ibtnRsServer = (ImageButton)e.Item.FindControl("ibtnRsServer");
            ImageButton ibtnRsOAudit = (ImageButton)e.Item.FindControl("ibtnRsOAudit");

            //判断主表是否已确认
            if (!Is_audit)
            {
                ibtnRsEdit.Visible = true;

                //不可编辑
                if (strButtonEdit.Trim() != "1")
                {

                    ibtnRsEdit.ImageUrl = "../App_Images/ico/14.gif";
                    ibtnRsEdit.ToolTip = "无编辑权限";
                }
            }
            else
            {
                ibtnRsOAudit.Visible = true;

                if (strButtonOAudit.Trim() != "5")
                {
                    ibtnRsOAudit.Enabled = false;
                    ibtnRsOAudit.ImageUrl = "../App_Images/ico/17.gif";
                }
            }

            //不可选择
            if (!this.panAudit.Visible && !this.panDelete.Visible)
            {
                chkRsSelect.Enabled = false;
            }

            //判断是否已作废
            if (Is_visible)
            {
                ibtnRsEdit.ImageUrl = "../App_Images/ico/14.gif";
                ibtnRsCancel.ImageUrl = "../App_Images/ico/18.gif";
                ibtnRsServer.ImageUrl = "../App_Images/ico/16.gif";
                ibtnRsOAudit.ImageUrl = "../App_Images/ico/17.gif";
                chkRsSelect.Enabled = ibtnRsEdit.Enabled = ibtnRsCancel.Enabled = ibtnRsServer.Enabled = ibtnRsOAudit.Enabled = false;
            }
        }
    }

    protected void dgrdResult_ItemCreated(object sender, DataGridItemEventArgs e)
    {
        if (e.Item.ItemType.ToString() == "Item" || e.Item.ItemType.ToString() == "AlternatingItem")
        {
            DataGrid dgrdChildResult = (DataGrid)e.Item.FindControl("dgrdChildResult");

            //子DataGrid注册事件
            dgrdChildResult.ItemDataBound += new DataGridItemEventHandler(dgrdChildResult_ItemDataBound);
        }
    }

    #endregion

    #region  费用报销业务逻辑其他部分

    public void ChangPage(object sender, EventArgs e)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();
        DataSet dst = cls_Property.SetOrGetCorporationDataSet;

        if (dst != null && dst.Tables[0].Rows.Count > 0)
        {
            string strKey = ((LinkButton)sender).CommandName;
            int intPageIndex = this.dgrdResult.CurrentPageIndex;
            int intPageCounts = this.dgrdResult.PageCount;

            if (strKey == "0")
            {
                intPageIndex = 0;
            }
            else if (strKey == "1")
            {
                if (intPageIndex > 0) intPageIndex -= 1;
            }
            else if (strKey == "2")
            {
                if (intPageIndex < intPageCounts - 1) intPageIndex += 1;
            }
            else
            {
                intPageIndex = intPageCounts - 1;
            }

            this.BindByDataView(dst, intPageIndex);
        }
    }

    public void ChildChangPage(object sender, EventArgs e)
    {
        //获取保存的从表中的结果集和DataGrid控件
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();
        DataSet dst = cls_Property.SetOrGetChildResultDataSet;
        DataGrid dgrd = cls_Property.SetOrGetChildDataGridControl;

        if (dst != null && dgrd != null)
        {
            string strKey = ((LinkButton)sender).CommandName;
            int intPageIndex = dgrd.CurrentPageIndex;
            int intPageCounts = dgrd.PageCount;

            if (strKey == "0")
            {
                intPageIndex = 0;
            }
            else if (strKey == "1")
            {
                if (intPageIndex > 0) intPageIndex -= 1;
            }
            else if (strKey == "2")
            {
                if (intPageIndex < intPageCounts - 1) intPageIndex += 1;
            }
            else
            {
                intPageIndex = intPageCounts - 1;
            }

            this.BindChildByDataView(dgrd, dst, intPageIndex);
        }
    }

    public void lbtnDelete_Click(object sender, EventArgs e)
    {
        int intCommandName = Int32.Parse(((LinkButton)sender).CommandName);

        this.DeleteStockCheckInfo(intCommandName);
    }

    public void lbtnQuery_Click(object sender, EventArgs e)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();

        string strUserID = cls_Property.SetOrGetUserID;

        if (strUserID != "")
        {
            int intCommandName = Int32.Parse(((LinkButton)sender).CommandName);

            this.GetInfoByMain(strUserID, intCommandName);
        }
        else
        {
            this.Page.Session.Remove("SetOrGetUserID");
            this.lblJs.Text = "<script>parent.window.location.href='../index.aspx'</script>";
        }
    }

    private void BindByDataView(DataSet dst, int CurrPageIndex)
    {
        if (dst != null && dst.Tables[0].Rows.Count > 0)
        {
            this.dgrdResult.CurrentPageIndex = CurrPageIndex;
            this.dgrdResult.DataSource = dst;
            this.dgrdResult.DataBind();

            this.lblRsCounts.Text = "共" + dst.Tables[0].Rows.Count + "条记录";
            this.lblPageCounts.Text = "共" + this.dgrdResult.PageCount + "页";
            this.lblCurrPage.Text = "当前第" + (this.dgrdResult.CurrentPageIndex + 1) + "页";
            this.lbtnFirst.Enabled = this.lbtnPrev.Enabled = this.lbtnNext.Enabled = this.lbtnEnd.Enabled = this.txtGo.Enabled = true;
            this.lblRsCounts.Enabled = this.lblPageCounts.Enabled = this.lblCurrPage.Enabled = this.lblGoTxt1.Enabled = this.lblGoTxt2.Enabled = true;

            if (this.dgrdResult.PageCount == 1)
            {
                this.lbtnFirst.Enabled = this.lbtnPrev.Enabled = this.lbtnNext.Enabled = this.lbtnEnd.Enabled = false;
                this.lblGoTxt1.Enabled = this.txtGo.Enabled = this.lblGoTxt2.Enabled = false;
            }
            else if (this.dgrdResult.CurrentPageIndex == this.dgrdResult.PageCount - 1)
            {
                this.lbtnNext.Enabled = this.lbtnEnd.Enabled = false;
            }
            else if (this.dgrdResult.CurrentPageIndex == 0)
            {
                this.lbtnFirst.Enabled = this.lbtnPrev.Enabled = false;
            }
        }
    }

    private void BindChildByDataView(DataGrid dgrd, DataSet dst, int CurrPageIndex)
    {
        if (dgrd != null && dst != null)
        {
            dgrd.CurrentPageIndex = CurrPageIndex;
            dgrd.DataSource = dst;
            dgrd.DataBind();

            int intIndex = Int32.Parse(dgrd.ToolTip);
            int intItems = dgrd.Items.Count;

            Label lblChildRsCounts = (Label)this.dgrdResult.Items[intIndex].FindControl("lblChildRsCounts");
            Label lblChildPageCounts = (Label)this.dgrdResult.Items[intIndex].FindControl("lblChildPageCounts");
            Label lblChildCurrPage = (Label)this.dgrdResult.Items[intIndex].FindControl("lblChildCurrPage");
            LinkButton lbtnChildFirst = (LinkButton)this.dgrdResult.Items[intIndex].FindControl("lbtnChildFirst");
            LinkButton lbtnChildPrev = (LinkButton)this.dgrdResult.Items[intIndex].FindControl("lbtnChildPrev");
            LinkButton lbtnChildNext = (LinkButton)this.dgrdResult.Items[intIndex].FindControl("lbtnChildNext");
            LinkButton lbtnChildEnd = (LinkButton)this.dgrdResult.Items[intIndex].FindControl("lbtnChildEnd");

            lblChildRsCounts.Text = "共" + dst.Tables[0].Rows.Count + "条明细记录";
            lblChildPageCounts.Text = "共" + dgrd.PageCount + "页";
            lblChildCurrPage.Text = "当前第" + (dgrd.CurrentPageIndex + 1) + "页";
            lbtnChildFirst.Enabled = lbtnChildPrev.Enabled = lbtnChildNext.Enabled = lbtnChildEnd.Enabled = true;
            lblChildRsCounts.Enabled = lblChildPageCounts.Enabled = lblChildCurrPage.Enabled = true;

            if (dgrd.PageCount == 1)
            {
                lbtnChildFirst.Enabled = lbtnChildPrev.Enabled = lbtnChildNext.Enabled = lbtnChildEnd.Enabled = false;
            }
            else if (dgrd.CurrentPageIndex == dgrd.PageCount - 1)
            {
                lbtnChildNext.Enabled = lbtnChildEnd.Enabled = false;
            }
            else if (dgrd.CurrentPageIndex == 0)
            {
                lbtnChildFirst.Enabled = lbtnChildPrev.Enabled = false;
            }

            //保存从表中的结果集和DataGrid控件用于从表中的翻页
            ClsPropertyDAL cls_Property = new ClsPropertyDAL();
            cls_Property.SetOrGetChildResultDataSet = dst;
            cls_Property.SetOrGetChildDataGridControl = dgrd;
        }
    }

    private void ControlButtonVisible(string UserLogID, string CurrPageID)
    {
        ClsMenuDAL cls_Menu = new ClsMenuDAL();

        //处理按钮权限
        DataSet dst = cls_Menu.GetCurrUserButtonPopedom(UserLogID, CurrPageID);

        if (dst != null && dst.Tables[0].Rows.Count > 0)
        {
            int intCount = dst.Tables[0].Rows.Count - 1;

            for (int i = intCount; i >= 0; i--)
            {
                int intButtonID = Int32.Parse(dst.Tables[0].Rows[i][2].ToString());

                switch (intButtonID)
                {
                    case 0:
                        this.panAdd.Visible = true;
                        break;
                    case 1:
                        this.hidButtonEdit.Value = intButtonID.ToString();
                        break;
                    case 2:
                        this.panDelete.Visible = true;
                        break;
                    case 3:
                        this.lbtnDelete1.Enabled = true;
                        break;
                    case 4:
                        this.panAudit.Visible = true;
                        break;
                    case 5:
                        this.hidButtonOAudit.Value = intButtonID.ToString();
                        break;
                    case 6:
                        this.panRef.Visible = true;
                        break;
                    case 7:
                        this.panSearch.Visible = true;
                        break;
                    case 8:
                        break;
                    case 9:
                        this.panQuery.Visible = true;
                        break;
                    case 10:
                        this.lbtnNotAudit.Enabled = true;
                        break;
                    case 11:
                        this.lbtnAuditing.Enabled = true;
                        break;
                    case 12:
                        this.lbtnEndAudit.Enabled = true;
                        break;
                    case 13:
                        break;
                    case 14:
                        break;
                    case 15:
                        this.lbtnNotCnacel.Enabled = true;
                        break;
                    case 16:
                        this.lbtnEndCnacel.Enabled = true;
                        break;
                    case 17:
                        break;
                    case 18:
                        break;
                    case 19:
                        this.lbtnAll.Enabled = true;
                        break;
                    case 20:
                        this.panPrint.Visible = true;
                        break;
                }
            }
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();

        string strUserID = cls_Property.SetOrGetUserID;

        if (strUserID != "")
        {
            if (!IsPostBack)
            {
                ////////////////按钮权限控制 Begin /////////////////////////
                string strCurrPageID = this.Page.Request.Params["PageID"];
                this.hidCurrPageID.Value = strCurrPageID;
                this.ControlButtonVisible(strUserID, strCurrPageID);
                //////////////////////  End ///////////////////////////////

                this.GetInfoByMain(strUserID, 5);
            }
            else
            {
                this.lblJs.Text = "";//清空Js脚本
            }

            this.ibtnDelete0.Attributes.Add("onClick", "return confirm('您真的要作废所选的项吗？');");
            this.lbtnDelete0.Attributes.Add("onClick", "return confirm('您真的要作废所选的项吗？');");
            this.lbtnDelete1.Attributes.Add("onClick", "return confirm('彻底作废将无法恢复数据。您真的要作废所选的项吗？');");
        }
        else
        {
            ClsMenuDAL cls_Menu = new ClsMenuDAL();
            string strMessage = cls_Menu.GetSystemCode("1", "00", this.ctbAdd0.Text.Trim(), 10);//取消当前系统编码
            this.Page.Session.Remove("SetOrGetUserID");
            this.lblJs.Text = "<script>parent.window.location.href='../index.aspx'</script>";
        }
    }

    protected void ibtnDelete0_Click(object sender, ImageClickEventArgs e)
    {
        int intCommandName = Int32.Parse(((ImageButton)sender).CommandName);

        this.DeleteStockCheckInfo(intCommandName);
    }

    protected void txtGo_TextChanged(object sender, EventArgs e)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();
        DataSet dst = cls_Property.SetOrGetCorporationDataSet;

        if (dst != null && dst.Tables[0].Rows.Count > 0)
        {
            string strIndex = this.txtGo.Text.Trim();
            this.txtGo.Text = String.Empty;

            if (strIndex != "")
            {
                try
                {
                    int intIndex = Int32.Parse(strIndex) - 1;

                    if (intIndex >= 0 && intIndex < this.dgrdResult.PageCount)
                    {
                        this.BindByDataView(dst, intIndex);
                    }
                    else
                    {
                        this.lblJs.Text = "<script>alert('请输入正确的页码数！')</script>";
                    }
                }
                catch
                {
                    this.lblJs.Text = "<script>alert('请输入数字类型的页码！')</script>";
                }
            }
            else
            {
                this.lblJs.Text = "<script>alert('请输入要跳转的页码！')</script>";
            }
        }
    }

    protected void ibtnRef_Click(object sender, ImageClickEventArgs e)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();

        string strUserID = cls_Property.SetOrGetUserID;

        if (strUserID != "")
        {
            int intCommand = Int32.Parse(((ImageButton)sender).CommandName);

            if (intCommand == 0)//刷新主表
            {
                this.GetInfoByMain(strUserID, cls_Property.SetOrGetDataSetType);
            }
            else//刷新从表
            {
                DataGrid dgrd = new DataGrid();
                string strCm_No = "";
                int intItems = this.dgrdResult.Items.Count;

                for (int i = intItems - 1; i >= 0; i--)//找当前可见的子DataGrid
                {
                    Panel panItem = (Panel)this.dgrdResult.Items[i].FindControl("panItem");

                    if (panItem.Visible)
                    {
                        dgrd = (DataGrid)this.dgrdResult.Items[i].FindControl("dgrdChildResult");
                        strCm_No = ((CuTextBox)this.dgrdResult.Items[i].FindControl("ctbRs0")).Text.Trim();
                        break;
                    }
                }

                ClsFeeReimDAL cls_FeeReimDAL = new ClsFeeReimDAL();
                DataSet dst = cls_FeeReimDAL.GetFeeReimChildDataSet(strCm_No);

                if (dst != null && dst.Tables[0].Rows.Count > 0)
                {
                    this.BindChildByDataView(dgrd, dst, 0);
                }
            }
        }
        else
        {
            this.Page.Session.Remove("SetOrGetUserID");
            this.lblJs.Text = "<script>parent.window.location.href='../index.aspx'</script>";
        }
    }

    protected void dgrdChildResult_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        if (e.Item.ItemIndex != -1)
        {
            //判断从表的可操作性(编辑和选择)
            string strButtonEdit = this.hidButtonEdit.Value;
            CheckBox chkChildRsSelect = (CheckBox)e.Item.FindControl("chkChildRsSelect");
            ImageButton ibtnChildRsEdit = (ImageButton)e.Item.FindControl("ibtnChildRsEdit");

            if (strButtonEdit.Trim() != "1")
            {
                ibtnChildRsEdit.Enabled = false;
                ibtnChildRsEdit.ImageUrl = "../App_Images/ico/14.gif";
            }

            //该主单是否已确认或终止
            int intIndex = Int32.Parse(((DataGrid)sender).ToolTip);
            bool is_audit = bool.Parse(this.dgrdResult.Items[intIndex].Cells[2].Text.Trim());
            bool is_visible = bool.Parse(this.dgrdResult.Items[intIndex].Cells[3].Text.Trim());

            if (is_audit || is_visible)
            {
                chkChildRsSelect.Enabled = ibtnChildRsEdit.Enabled = false;
                ibtnChildRsEdit.ImageUrl = "../App_Images/ico/14.gif";
            }
            else if (!this.panDelete.Visible)
            {
                chkChildRsSelect.Enabled = false;
            }
        }
    }

    protected void ImgbtnNotAudit_Click(object sender, ImageClickEventArgs e)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();

        string strUserID = cls_Property.SetOrGetUserID;

        if (strUserID != "")
        {
            int intCommandName = Int32.Parse(((ImageButton)sender).CommandName);

            this.GetInfoByMain(strUserID, intCommandName);
        }
        else
        {
            this.Page.Session.Remove("SetOrGetUserID");
            this.lblJs.Text = "<script>parent.window.location.href='../index.aspx'</script>";
        }
    }

    #endregion
}
